package com.springboot.erp.controller;

import com.springboot.erp.common.CommonResult;
import com.springboot.erp.entity.IncomeDTO;
import com.springboot.erp.entity.JshAccountHead;
import com.springboot.erp.service.IncomeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/income")
@Slf4j
public class IncomeController {

    @Resource
    private IncomeService incomeService;
    @GetMapping("/{id}")
    public CommonResult<IncomeDTO> selectIncomeById(@PathVariable Long id) {
        // 添加 @PathVariable 注解，绑定路径变量
        return CommonResult.success(incomeService.selectIncomeById(id));
    }
    @GetMapping("/listIncomes")
    public CommonResult<List<JshAccountHead>> listIncomes(Long organId, String status, Date startDate, Date endDate) {
        List<JshAccountHead> incomes = incomeService.listIncomes(organId, status, startDate, endDate);
        return CommonResult.success(incomes);
    }

    @PostMapping
    public CommonResult<Void> addOne(@RequestBody JshAccountHead jshAccountHead) {
        incomeService.addOne(jshAccountHead);
        return new CommonResult( 0, "success", null);
    }
    @PutMapping
    public CommonResult<Void> updateOne(@RequestBody JshAccountHead jshAccountHead) {
        incomeService.updateOne(jshAccountHead);
        return new CommonResult( 0, "success", null);
    }
    @DeleteMapping("/{id}")
    public CommonResult<Void> deleteOne(@PathVariable Integer id) {
        incomeService.deleteOne(id);
        return new CommonResult( 0, "success", null);
    }

}